/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Random;
import java.util.Scanner;

/**
 * <p>Project: jse2204 - GuessNum
 * <p>Powered by webrx On 2022-09-02 17:39:26
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class GuessNum {
    public static void main(String[] args) {
        //1.随机生成一个1-100的随机整数
        Random rand = new Random();
        int a = 1;
        int b = 100;
        int n = rand.nextInt(a, b + 1);

        int i = 0;
        //2.条件循环语句
        while (true) {
            if(i>=10){
                System.err.printf("%d、游戏结束，智商太低，游戏：（%d）分。%n", i, 0);
                break;
            }
            System.out.printf("请输入数字[%d-%d]:%n", a, b);

            //3.键盘输入数字
            int t = new Scanner(System.in).nextInt();
            ++i;

            if (t == n) {
                System.out.printf("%d、恭喜您，猜对了，你的游戏：（%d）分。%n", i, (100 - i * 10 + 10));

                //退出循环语句
                break;
            } else if (t > n) {
                System.out.printf("%d、太大了。%n", i);
            } else {
                System.out.printf("%d、太小了。%n", i);
            }
        }
    }
}
